package com.example.test2;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        //创建驱动对象
        EdgeOptions options = new EdgeOptions();
        options.addArguments("--remote-allow-origins=*");
        EdgeDriver driver = new EdgeDriver(options);

        //等待3秒
        Thread.sleep(3000);

        //在浏览器里输入百度网址，访问百度首页
        driver.get("https://www.baidu.com");

        Thread.sleep(3000);

        System.out.println("内容："+driver.findElement(By.cssSelector("#hotsearch-content-wrapper > li:nth-child(1) > a > span.title-content-title")).getText());//getText：获取文本

        System.out.println("属性："+driver.findElement(By.cssSelector("#su")).getAttribute("value"));//getAttribute：获取属性对应的值

        System.out.println("标题："+driver.getTitle());//getTitle：获取标题

        System.out.println("Url："+driver.getCurrentUrl());//getCurrentUrl：获取Url

        //自动化操作
        //①具体操作：先找到元素，返回类型为WebElement类型
        //WebElement element = driver.findElement(By.cssSelector("#kw"));
        //找到元素后，在进行操作
        //element.sendKeys("拼命阿紫");
        //②复合操作：先找到元素，然后操作
        driver.findElement(By.cssSelector("#kw")).sendKeys("拼命阿紫");//sendKeys:输入

        Thread.sleep(3000);

        driver.findElement(By.cssSelector("#kw")).clear();//清空

        Thread.sleep(3000);

        driver.findElement(By.cssSelector("#kw")).sendKeys("程序猿教你打篮球");

        Thread.sleep(3000);

        driver.findElement(By.cssSelector("#su")).click();//click：点击

        Thread.sleep(3000);

        //结束会话（关闭浏览器）
        driver.quit();


    }
}
